package bb.lanxing.model.json;

import com.baidu.mapapi.model.LatLng;
import com.orm.SugarRecord;
import com.orm.dsl.Ignore;
import com.orm.dsl.Table;
import com.orm.query.Select;
import com.umeng.analytics.pro.z;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import bb.lanxing.App;
import bb.lanxing.common.config.Constants;
import bb.lanxing.util.DistanceUtil;
import bb.lanxing.util.JsonUtil;

@Table(name = "club")
public class Club extends SugarRecord implements Serializable {
    public static final int TEAM_STATE_APPLYING = 0;
    public static final int TEAM_STATE_JOINED = 1;
    public static final int TEAM_STATE_LEAVE = 2;
    private String avatar;
    private String captainAvatar;
    private long captainId;
    private String captainName;
    private String city;
    private int cityId;
    @Ignore
    private long cityRank;
    private long clubId;
    private String createTime;
    @Ignore
    private int cupCount;
    private String description;
    @Ignore
    private int isPartner;
    private double latitude;
    private double longitude;
    @Ignore
    private List<ClubMedalSmall> medalSmalls;
    private int memberCount;
    @Ignore
    private int monthHots;
    private double mouthDistance;
    private String notice;
    @Ignore
    private int peopleAverageHotValue;
    @Ignore
    private int planEventCount;
    private String province;
    private String tag;
    private int teamApplyCounts;
    private int teamStatus;
    private String title;
    private double totalDistance;
    private long userId;
    @Ignore
    private int yearHots;

    private Long id;

    public Club() {
    }

    public Club(JSONObject jSONObject) {
//        JSONObject objectValue = JsonUtil.getObjectValue(z.m, jSONObject);
//        if (objectValue != null) {
//            ServerUser serverUser = new ServerUser(objectValue);
//            setCaptainId(serverUser.getUserId());
//            setCaptainName(serverUser.getName());
//            setCaptainAvatar(serverUser.getPhotoUrl());
//        }
        setClubId(JsonUtil.getLongValue("teamId", jSONObject));
        setTitle(JsonUtil.getStringValue("teamTitle", jSONObject));
        setDescription(JsonUtil.getStringValue("teamDesc", jSONObject));
        setMemberCount(JsonUtil.getIntegerValue("teamUserCounts", jSONObject));
        setAvatar(JsonUtil.getStringValue("teamAvatar", jSONObject));
        setNotice(JsonUtil.getStringValue("teamNotice", jSONObject));
        setCityId(JsonUtil.getIntegerValue("teamCityId", jSONObject));
        setCity(JsonUtil.getStringValue("teamCityName", jSONObject));
        setTotalDistance(JsonUtil.getDoubleValue("teamTotalMiles", jSONObject));
        setMouthDistance(JsonUtil.getDoubleValue("teamMonthMiles", jSONObject));
        setCreateTime(JsonUtil.getStringValue("teamCreateTime", jSONObject));
        setTeamStatus(JsonUtil.getIntegerValue("teamStatus", jSONObject));
        setTeamApplyCounts(JsonUtil.getIntegerValue("teamApplyCounts", jSONObject));
        setUserId(App.getContext().getUserId());
        setTag(JsonUtil.getStringValue("tag", jSONObject));
        setMonthHots(JsonUtil.getIntegerValue("month_hots", jSONObject));
        setYearHots(JsonUtil.getIntegerValue("year_hots", jSONObject));
        setIsPartner(JsonUtil.getIntegerValue("is_partner", jSONObject));
        setPeopleAverageHotValue(JsonUtil.getIntegerValue("avg_month_hots", jSONObject));
        setCityRank(JsonUtil.getLongValue("city_rank", jSONObject));
        setCupCount(JsonUtil.getIntegerValue("all_cups", jSONObject));
        setPlanEventCount(JsonUtil.getIntegerValue("activity_num", jSONObject));
        JSONArray arrayValue = JsonUtil.getArrayValue("medal_small", jSONObject);
        ArrayList arrayList = new ArrayList();
        for (int i = 0; arrayValue != null && i < arrayValue.length(); i++) {
            try {
                arrayList.add(new ClubMedalSmall(arrayValue.getJSONObject(i)));
            } catch (JSONException unused) {
            }
        }
        this.medalSmalls = arrayList;
    }

    public static Club getByClubId(long j) {
        return (Club) Select.from(Club.class).where("club_id = ?", new String[]{String.valueOf(j)}).first();
    }

    public static Club getByClubId(long j, long j2) {
        return (Club) Select.from(Club.class).where("user_id = ? and club_id = ?", new String[]{String.valueOf(j2), String.valueOf(j)}).first();
    }

    public static List<Club> getMyClubs() {
        return Select.from(Club.class).where("user_id = ? and team_status <= 1", new String[]{String.valueOf(App.getContext().getUserId())}).list();
    }

    public static List<Club> getMyJoinedClubs() {
        return Select.from(Club.class).where("user_id = ? and team_status = 1", new String[]{String.valueOf(App.getContext().getUserId())}).list();
    }

    public static void clearMyClubs() {
        deleteAll(Club.class, "user_id = ?", String.valueOf(App.getContext().getUserId()));
    }

    public static Comparator<Club> getComparator(final LatLng latLng) {
        return new Comparator<Club>() {
            @Override
            public int compare(Club club, Club club2) {
//                return DistanceUtil.get(LatLng.this, new LatLng(club.getLatitude(), club.getLongitude())) >= DistanceUtil.get(LatLng.this, new LatLng(club2.getLatitude(), club2.getLongitude())) ? 1 : -1;
                return 1;
            }
        };
    }

    public String getCaptainName() {
        return this.captainName;
    }

    public void setCaptainName(String str) {
        this.captainName = str;
    }

    public String getCaptainAvatar() {
        return this.captainAvatar;
    }

    public void setCaptainAvatar(String str) {
        this.captainAvatar = str;
    }

    public String getBigPhoto() {
        return this.avatar + Constants.UPYUN_IMAGE_TYPE_PHOTO;
    }

    public int getTeamStatus() {
        return this.teamStatus;
    }

    public void setTeamStatus(int i) {
        this.teamStatus = i;
    }

    public int getTeamApplyCounts() {
        return this.teamApplyCounts;
    }

    public void setTeamApplyCounts(int i) {
        this.teamApplyCounts = i;
    }

    public long getUserId() {
        return this.userId;
    }

    public void setUserId(long j) {
        this.userId = j;
    }

    public String getNotice() {
        return this.notice;
    }

    public void setNotice(String str) {
        this.notice = str;
    }

    public int getCityId() {
        return this.cityId;
    }

    public void setCityId(int i) {
        this.cityId = i;
    }

    public long getCaptainId() {
        return this.captainId;
    }

    public void setCaptainId(long j) {
        this.captainId = j;
    }

    public String getAvatar() {
        return this.avatar;
    }

    public void setAvatar(String str) {
        this.avatar = str;
    }

    public String getProvince() {
        return this.province;
    }

    public void setProvince(String str) {
        this.province = str;
    }

    public double getTotalDistance() {
        return this.totalDistance;
    }

    public void setTotalDistance(double d) {
        this.totalDistance = d;
    }

    public double getMouthDistance() {
        return this.mouthDistance;
    }

    public void setMouthDistance(double d) {
        this.mouthDistance = d;
    }

    public String getCity() {
        return this.city;
    }

    public void setCity(String str) {
        this.city = str;
    }

    public String getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(String str) {
        this.createTime = str;
    }

    public long getClubId() {
        return this.clubId;
    }

    public void setClubId(long j) {
        this.clubId = j;
        this.id = j;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String str) {
        this.title = str;
    }

    public int getMemberCount() {
        return this.memberCount;
    }

    public void setMemberCount(int i) {
        this.memberCount = i;
    }

    public double getLatitude() {
        return this.latitude;
    }

    public void setLatitude(double d) {
        this.latitude = d;
    }

    public double getLongitude() {
        return this.longitude;
    }

    public void setLongitude(double d) {
        this.longitude = d;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String str) {
        this.description = str;
    }

    public String getTag() {
        return this.tag;
    }

    public int getMonthHots() {
        return this.monthHots;
    }

    public void setMonthHots(int i) {
        this.monthHots = i;
    }

    public int getYearHots() {
        return this.yearHots;
    }

    public void setYearHots(int i) {
        this.yearHots = i;
    }

    public int getPeopleAverageHotValue() {
        return this.peopleAverageHotValue;
    }

    public void setPeopleAverageHotValue(int i) {
        this.peopleAverageHotValue = i;
    }

    public long getCityRank() {
        return this.cityRank;
    }

    public void setCityRank(long j) {
        this.cityRank = j;
    }

    public int getCupCount() {
        return this.cupCount;
    }

    public void setCupCount(int i) {
        this.cupCount = i;
    }

    public int getPlanEventCount() {
        return this.planEventCount;
    }

    public void setPlanEventCount(int i) {
        this.planEventCount = i;
    }

    public int getIsPartner() {
        return this.isPartner;
    }

    public void setIsPartner(int i) {
        this.isPartner = i;
    }

    public String[] getTags() {
        String str = this.tag;
        if (str != null) {
            return str.split(";");
        }
        return null;
    }

    public void setTag(String str) {
        this.tag = str;
    }

    public List<ClubMedalSmall> getMedalSmalls() {
        return this.medalSmalls;
    }
}
